package com.joysuch.wwyt.bp.entity.inspect;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.joysuch.wwyt.core.support.AutoSetCommonFieldListener;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLDeleteAll;
import org.hibernate.annotations.Where;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.time.LocalDate;
import java.time.LocalTime;

import static javax.persistence.GenerationType.IDENTITY;

/**
 * @Author ZhangDong
 * @Date 2020/3/10 16:36
 */
@EntityListeners({AuditingEntityListener.class, AutoSetCommonFieldListener.class})
@Entity
@Table(name = "wwyt_bp_judge_app_plan_task")
@SQLDelete(sql = "update wwyt_bp_judge_app_plan_task set DELETE_FLAG = '1' where id= ?")
@SQLDeleteAll(sql = "update wwyt_bp_judge_app_plan_task set DELETE_FLAG = '1' where id= ?")
@Where(clause = "DELETE_FLAG = '0'")
@Data
public class BpAppPlanTask {

    @Id
    @GeneratedValue(strategy = IDENTITY)
    @ApiModelProperty("主键id")
    private Long id;

    @ApiModelProperty("计划表主键id")
    private Long planId;

    @ApiModelProperty("巡检人员id")
    private Long checkUserId;

    @ApiModelProperty("巡检人员姓名")
    private String checkUserName;

    @ApiModelProperty("检查日期-计算得出")
    private LocalDate checkDate;

    @ApiModelProperty("检查时间-计算得出")
    private LocalTime checkTime;

    @ApiModelProperty("允许开始执行误差时间-分钟")
    private Integer permitDeviationTime;

    @ApiModelProperty("任务状态: 待完成 未完成 已完成")
    private String status;

    @ApiModelProperty("任务状态详情 eg:已过期")
    private String statusDetail;

    @ApiModelProperty("是否是多人任务: 0 不是; 1 是")
    private Integer multiUserTaskFlag;

    @ApiModelProperty("任务接收任务人id")
    private Long acceptTaskUserId;

    @ApiModelProperty("任务Id")
    private Integer taskId;

    @ApiModelProperty("关联记录表id")
    private Long recordId;

    @ApiModelProperty("创建时间")
    @org.springframework.data.annotation.CreatedDate
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private java.time.LocalDateTime createTime;

    @ApiModelProperty("租户")
    private Long tenentId;

    @ApiModelProperty("组织机构代码")
    private String orgCode;

    @ApiModelProperty("删除标记")
    @JsonIgnore
    private String deleteFlag;

    public BpAppPlanTask() {
    }

    public BpAppPlanTask(Long planId, Long checkUserId, String checkUserName, LocalDate checkDate, LocalTime checkTime,
                         String status, Integer multiUserTaskFlag, Integer taskId, Integer permitDeviationTime) {
        this.planId = planId;
        this.checkUserId = checkUserId;
        this.checkUserName = checkUserName;
        this.checkDate = checkDate;
        this.checkTime = checkTime;
        this.status = status;
        this.multiUserTaskFlag = multiUserTaskFlag;
        this.taskId = taskId;
        this.permitDeviationTime = permitDeviationTime;
    }

    @Override
    public String toString() {
        return "BpAppPlanTask{" +
                "id=" + id +
                ", planId=" + planId +
                ", checkUserId=" + checkUserId +
                ", checkUserName='" + checkUserName + '\'' +
                ", checkDate=" + checkDate +
                ", checkTime=" + checkTime +
                ", permitDeviationTime=" + permitDeviationTime +
                ", status='" + status + '\'' +
                ", statusDetail='" + statusDetail + '\'' +
                ", multiUserTaskFlag=" + multiUserTaskFlag +
                ", acceptTaskUserId=" + acceptTaskUserId +
                ", taskId=" + taskId +
                ", createTime=" + createTime +
                ", tenentId=" + tenentId +
                ", orgCode='" + orgCode + '\'' +
                ", deleteFlag='" + deleteFlag + '\'' +
                '}';
    }
}
